-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Don't assume traits used as type are trait objs in 2021 edition #131239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @lcnr (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
HIR ty lowering was modified cc @fmease |
@rustbot author |
FYI the word "vunlnerability" has a specific meaning (i.e. a weakness that makes something easy to be attacked/exploited) in the context of this repo (e.g. related to compiler or std), but this PR is just trying to improve diagnostics not trying to address an exploit. |
I see vulnerability as when something is not right and I fix it. Ok I will change the word |
We usually call those those "bugs" or "diagnostic issues", "vulnerability" usually indicates an exploitable weakness that has to do with security that wg-security-response would need to look at. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
4481349
to
6a66761
Compare
@rustbot review |
71f96e3
to
6037e9e
Compare
This comment has been minimized.
This comment has been minimized.
a28d963
to
60f3737
Compare
r=me after CI |
60f3737
to
16fe4ce
Compare
☔ The latest upstream changes (presumably #131511) made this pull request unmergeable. Please resolve the merge conflicts. |
16fe4ce
to
9a2772e
Compare
@bors r+ rollup |
…lcnr Don't assume traits used as type are trait objs in 2021 edition Fixes rust-lang#127548 When you use a trait as a type, the compiler automatically assumes you meant to use a trait object, which is not always the case. This PR fixes the bug where you don't need a trait object, so the error message was changed to: ``` error[E0782]: expected a type, found a trait ``` Also fixes some ICEs: Fixes rust-lang#120241 Fixes rust-lang#120482 Fixes rust-lang#125512
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#130870 (Add suggestion for removing invalid path sep `::` in fn def) - rust-lang#131233 (std: fix stdout-before-main) - rust-lang#131239 (Don't assume traits used as type are trait objs in 2021 edition) - rust-lang#131277 (Handle `clippy` cases of `rustc::potential_query_instability` lint) - rust-lang#131567 (Emit an error for unstable attributes that reference already stable features) - rust-lang#131585 (compiletest: Remove the one thing that was checking a directive's `original_line`) - rust-lang#131590 (yeet some clones) - rust-lang#131597 (Take a display name for `tool_check_step!`) r? `@ghost` `@rustbot` modify labels: rollup
…lcnr Don't assume traits used as type are trait objs in 2021 edition Fixes rust-lang#127548 When you use a trait as a type, the compiler automatically assumes you meant to use a trait object, which is not always the case. This PR fixes the bug where you don't need a trait object, so the error message was changed to: ``` error[E0782]: expected a type, found a trait ``` Also fixes some ICEs: Fixes rust-lang#120241 Fixes rust-lang#120482 Fixes rust-lang#125512
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#128784 (Check ABI target compatibility for function pointers) - rust-lang#130965 (make `Step` doc-comments more clear) - rust-lang#131239 (Don't assume traits used as type are trait objs in 2021 edition) - rust-lang#131277 (Handle `clippy` cases of `rustc::potential_query_instability` lint) - rust-lang#131503 (More clearly document Stdin::read_line) - rust-lang#131567 (Emit an error for unstable attributes that reference already stable features) - rust-lang#131599 (Shallowly match opaque key in storage) - rust-lang#131617 (remove const_cow_is_borrowed feature gate) Failed merges: - rust-lang#131616 (merge const_ipv4 / const_ipv6 feature gate into 'ip' feature gate) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#131239 - VulnBandit:trait-vulnerability, r=lcnr Don't assume traits used as type are trait objs in 2021 edition Fixes rust-lang#127548 When you use a trait as a type, the compiler automatically assumes you meant to use a trait object, which is not always the case. This PR fixes the bug where you don't need a trait object, so the error message was changed to: ``` error[E0782]: expected a type, found a trait ``` Also fixes some ICEs: Fixes rust-lang#120241 Fixes rust-lang#120482 Fixes rust-lang#125512
…=davidtwco Improve parse errors for stray lifetimes in type position While technically & syntactically speaking lifetimes do begin[^1] types in type contexts (this essentially excludes generic argument lists) and require a following `+` to form a complete type (`'a +` denotes a bare trait object type), the likelihood that a user meant to write a lifetime-prefixed bare trait object type in *modern* editions (Rust ≥2021) when placing a lifetime into a type context is incredibly low (they would need to add at least three tokens to turn it into a *semantically* well-formed TOT: `'a` → `dyn 'a + Trait`). Therefore let's *lie* in modern editions (just like in PR rust-lang#131239, a precedent if you will) by stating "*expected type, found lifetime*" in such cases which is a lot more a approachable, digestible and friendly compared to "*lifetime in trait object type must be followed by `+`*" (as added in PR rust-lang#69760). I've also added recovery for "ampersand-less" reference types (e.g., `'a ()`, `'a mut Ty`) in modern editions because it was trivial to do and I think it's not unlikely to occur in practice. Fixes rust-lang#133413. [^1]: For example, in the context of decl macros, this implies that a lone `'a` always matches syntax fragment `ty` ("even if" there's a later macro matcher expecting syntax fragment `lifetime`). Rephrased, lifetimes (in type contexts) *commit* to the type parser.
Fixes #127548
When you use a trait as a type, the compiler automatically assumes you meant to use a trait object, which is not always the case.
This PR fixes the bug where you don't need a trait object, so the error message was changed to:
Also fixes some ICEs:
Fixes #120241
Fixes #120482
Fixes #125512